package org.setec.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Utils {


    public static Class[] objectClasses(Object[] objects){
        Class[] classes = new Class[objects == null ? 0 : objects.length];
        for (int i = 0; objects != null && i < objects.length; i++) {
            classes[i] = objects[i].getClass();
        }
        return classes;
    }


    public static String getMD5Hash(byte[] data) {
         try {
             MessageDigest md5 = MessageDigest.getInstance("MD5");
             byte result[] = md5.digest(data);
             StringBuffer sb = new StringBuffer();
             for (int i = 0; i < result.length; i++) {
                 String s = Integer.toHexString(result[i]);
                 int length = s.length();
                 if (length >= 2) {
                     sb.append(s.substring(length - 2, length));
                 } else {
                     sb.append("0");
                     sb.append(s);
                 }
             }
             return sb.toString();
         } catch (NoSuchAlgorithmException e) {
             return null;
         }
     }

}
